import { getToken } from '@/utils/token';
import { Button, Upload } from 'antd';
import styles from './index.less';

const TrackInfo = (props) => {
  const { lineId } = props;
  return (
    <div className={styles.trackInfo}>
      <header className={styles.header}>
        <Upload
          name="file"
          action={`/datas/line/import/points?lineId=${lineId}`}
          showUploadList={false}
          headers={{
            token: getToken(),
          }}
          onChange={(info) => {
            if (info?.file?.status === 'done') {
              if (info?.file?.response?.code === 200) {
                message.success('导入成功');
                // TODO: 导入后渲染地图
              }
            }
          }}
        >
          <Button type="primary" size="small">
            导入轨迹
          </Button>
        </Upload>
        <Button
          type="primary"
          size="small"
          onClick={() => window.open('/logistics/tracker_template.xls')}
        >
          模板下载
        </Button>
      </header>
      <section className={styles.section}>轨迹组件</section>
    </div>
  );
};

export default TrackInfo;
